package com.qyer.search.model.lastminute;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.qyer.search.filter.AbstractFilter;
import com.qyer.search.model.SearchParameter;
import com.qyer.search.model.SearchParameterOrigin;

import java.util.List;
import java.util.*;

/**
 * Created by tangzheng on 16/7/18.
 */
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY)
@JsonIgnoreProperties(ignoreUnknown = true)
public abstract class ZSKU {

  public static final String FIELD_ID = "lid";
  public static final String FIELD_TITLE = "title";
  public static final String FIELD_TYPE1 = "cid";
  public static final String FIELD_TYPE2 = "ccid";
  public static final String FIELD_COUNTRIES = "countries";
  public static final String FIELD_CITIES = "cities";
  public static final String FIELD_CHANNELS = "channels";
  public static final String FIELD_START_TIME = "start_time";
  public static final String FIELD_END_TIME = "end_time";
  public static final String FIELD_VERSION = "version";

  public static final String FIELD_TAGS = "tags";
  public static final String FIELD_Z_TAGS = "z_tags";
  public static final String FIELD_TRAVELDAY = "travel_day";
  public static final String FIELD_SOURCE_PLACE = "set_out_place";
  public static final String FIELD_ONSALE_TIME = "onsaleTime";
  public static final String FIELD_OFFSET_TIME = "offsetTime";
  public static final String FIELD_ZTAG_IDS = "z_tags.tid";

  public static final String[] RETAIN_FIELDS = new String[]{FIELD_ID, FIELD_TYPE1, FIELD_TYPE2,
                                                            FIELD_CHANNELS,FIELD_START_TIME,FIELD_END_TIME};
  public static final String[] RETAIN_FIELDS_BASIC = new String[]{FIELD_ID, FIELD_TYPE1, FIELD_TYPE2,
                                                                  FIELD_CHANNELS,FIELD_START_TIME,FIELD_END_TIME,FIELD_TAGS};
  public static final String[] RETAIN_RICH = new String[]{FIELD_ID, FIELD_TYPE1, FIELD_TYPE2,
                                                          FIELD_CHANNELS,FIELD_START_TIME,FIELD_END_TIME,FIELD_TAGS,FIELD_Z_TAGS};
  public static final String[] RETAIN_LIGHT = new String[]{FIELD_ID,
                                                           FIELD_CHANNELS,FIELD_START_TIME,FIELD_END_TIME,
                                                           FIELD_TAGS,FIELD_Z_TAGS,FIELD_TRAVELDAY,FIELD_TITLE,
                                                           FIELD_SOURCE_PLACE,FIELD_CITIES,FIELD_COUNTRIES,FIELD_ONSALE_TIME,FIELD_OFFSET_TIME};

  public static final String[] RETAIN_LIGHT_LESS = new String[]{FIELD_ID,
                                                    FIELD_CHANNELS,FIELD_START_TIME,FIELD_END_TIME,FIELD_Z_TAGS,FIELD_ONSALE_TIME};


  public static final String[] RETAIN_SIMPLE = new String[]{FIELD_ID};
  public static final String FIELD_OUT_ID = "lid";
  public static final String FIELD_OUT_TITLE = "title";
  public static final String FIELD_OUT_TYPE1 = "type1";
  public static final String FIELD_OUT_TYPE2 = "type2";
  //  public static final String FIELD_OUT_COUNTRIES = "countries";
  //  public static final String FIELD_OUT_CITIES = "cities";
  //  public static final String FIELD_CHANNELS = "channels";
  public static final String FIELD_OUT_TAGS = "tags";
  //public static final String FIELD_SOURCE_PLACE = "set_out_place";
  public static final String FIELD_SUPPLIERID = "supplierid";

  public static final String FIELD_OUT_BASIC_COUNTRIES = "countries";
  public static final String FIELD_OUT_BASIC_CITIES = "cities";
  public static final String FIELD_OUT_BASIC_CONTINENT = "continents";

  public static SKU build(SearchParameter sp, Map<String, Object> dataMap, boolean simple) {
    return simple ? SimpleSKU.build(sp, dataMap) : RichSKU.build(sp, dataMap);
  }

  public static SKU build(SearchParameterOrigin sp, Map<String, Object> dataMap, boolean simple) {
    return simple ? SimpleSKU.build(sp, dataMap) : RichSKU.build(sp, dataMap);
  }

  public static SKU build(SearchParameterOrigin sp, Map<String, Object> dataMap, boolean simple,
                          List<AbstractFilter> filters) {
    return simple ? SimpleSKU.build(sp, dataMap, filters) : RichSKU.build(sp, dataMap, filters);
  }

  public static SKU build(SearchParameterOrigin sp, Map<String, Object> dataMap, boolean simple,
                          Map<Integer,Map<Integer,Integer>> placeSearchCensus,
                          Map<Integer,Map<Integer,Integer>> typeSearchCensus) {
    return simple ? SimpleSKU.build(sp, dataMap, placeSearchCensus, typeSearchCensus) :
           RichSKU.build(sp, dataMap, placeSearchCensus, typeSearchCensus);
  }

  public static SKU build(SearchParameterOrigin sp, Map<String, Object> dataMap, boolean simple,
                          List<AbstractFilter> filters,
                          Map<Integer,Map<Integer,Integer>> placeSearchCensus,
                          Map<Integer,Map<Integer,Integer>> typeSearchCensus) {
    return simple ? SimpleSKU.build(sp, dataMap, filters, placeSearchCensus, typeSearchCensus) :
           RichSKU.build(sp, dataMap, filters, placeSearchCensus, typeSearchCensus);
  }

  public static SKU buildBasicSKU(SearchParameterOrigin sp, Map<String, Object> dataMap) {
    return BasicSKU.build(sp, dataMap);
  }

  public static SKU buildBasicSKU(SearchParameterOrigin sp, Map<String, Object> dataMap,
                                  Map<Integer,Map<Integer,Integer>> placeSearchCensus,
                                  Map<Integer,Map<Integer,Integer>> typeSearchCensus) {
    return BasicSKU.build(sp, dataMap, placeSearchCensus, typeSearchCensus);
  }

  public static SKU buildBasicSKU(SearchParameterOrigin sp, Map<String, Object> dataMap,
                                  List<AbstractFilter> filters) {
    return BasicSKU.build(sp, dataMap, filters);
  }

  public static SKU buildBasicSKU(SearchParameterOrigin sp, Map<String, Object> dataMap,
                                  List<AbstractFilter> filters,
                                  Map<Integer,Map<Integer,Integer>> placeSearchCensus,
                                  Map<Integer,Map<Integer,Integer>> typeSearchCensus) {
    return BasicSKU.build(sp, dataMap, filters, placeSearchCensus, typeSearchCensus);
  }

  public ZSKU() {
  }

  public abstract int getId();

  public abstract Set<Integer> getType1();

  public abstract Set<Integer> getType2();

  public abstract int getMarket_info();

  public abstract String getTitle();

  public static String unknownPositionSKU(int skuId) {
    return "SKU(" + skuId + ")-UnknownPosition";
  }

  public static String naSKU(int skuId) {
    return "SKU(" + skuId + ")-NotAvailable";
  }
}

